{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "be0765f0",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "bc9372e2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>1</th>\n",
       "      <th>Mickéy Mousé</th>\n",
       "      <th>56</th>\n",
       "      <th>70kgs</th>\n",
       "      <th>72</th>\n",
       "      <th>69</th>\n",
       "      <th>71</th>\n",
       "      <th>-</th>\n",
       "      <th>-.1</th>\n",
       "      <th>-.2</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2.0</td>\n",
       "      <td>Donald Duck</td>\n",
       "      <td>34.0</td>\n",
       "      <td>154.89lbs</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>85</td>\n",
       "      <td>84</td>\n",
       "      <td>76</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>3.0</td>\n",
       "      <td>Mini Mouse</td>\n",
       "      <td>16.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>65</td>\n",
       "      <td>69</td>\n",
       "      <td>72</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>4.0</td>\n",
       "      <td>Scrooge McDuck</td>\n",
       "      <td>NaN</td>\n",
       "      <td>78kgs</td>\n",
       "      <td>78</td>\n",
       "      <td>79</td>\n",
       "      <td>72</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>5.0</td>\n",
       "      <td>Pink Panther</td>\n",
       "      <td>54.0</td>\n",
       "      <td>198.658lbs</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>69</td>\n",
       "      <td>NaN</td>\n",
       "      <td>75</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>6.0</td>\n",
       "      <td>Huey McDuck</td>\n",
       "      <td>52.0</td>\n",
       "      <td>189lbs</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>68</td>\n",
       "      <td>75</td>\n",
       "      <td>72</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>7.0</td>\n",
       "      <td>Dewey McDuck</td>\n",
       "      <td>19.0</td>\n",
       "      <td>56kgs</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>71</td>\n",
       "      <td>78</td>\n",
       "      <td>75</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>8.0</td>\n",
       "      <td>Scööpy Doo</td>\n",
       "      <td>32.0</td>\n",
       "      <td>78kgs</td>\n",
       "      <td>78</td>\n",
       "      <td>76</td>\n",
       "      <td>75</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>9.0</td>\n",
       "      <td>Huey McDuck</td>\n",
       "      <td>52.0</td>\n",
       "      <td>189lbs</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>68</td>\n",
       "      <td>75</td>\n",
       "      <td>72</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>10.0</td>\n",
       "      <td>Louie McDuck</td>\n",
       "      <td>12.0</td>\n",
       "      <td>45kgs</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>92</td>\n",
       "      <td>95</td>\n",
       "      <td>87</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      1    Mickéy Mousé    56       70kgs   72   69   71    -  -.1  -.2\n",
       "0   2.0     Donald Duck  34.0   154.89lbs    -    -    -   85   84   76\n",
       "1   3.0      Mini Mouse  16.0         NaN    -    -    -   65   69   72\n",
       "2   4.0  Scrooge McDuck   NaN       78kgs   78   79   72    -    -    -\n",
       "3   5.0    Pink Panther  54.0  198.658lbs    -    -    -   69  NaN   75\n",
       "4   6.0     Huey McDuck  52.0      189lbs    -    -    -   68   75   72\n",
       "5   7.0    Dewey McDuck  19.0       56kgs    -    -    -   71   78   75\n",
       "6   8.0      Scööpy Doo  32.0       78kgs   78   76   75    -    -    -\n",
       "7   NaN             NaN   NaN         NaN  NaN  NaN  NaN  NaN  NaN  NaN\n",
       "8   9.0     Huey McDuck  52.0      189lbs    -    -    -   68   75   72\n",
       "9  10.0    Louie McDuck  12.0       45kgs    -    -    -   92   95   87"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.read_csv('./data/patient_heart_rate.csv')\n",
    "df.head(10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "8f4facc5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>id</th>\n",
       "      <th>name</th>\n",
       "      <th>age</th>\n",
       "      <th>weight</th>\n",
       "      <th>m0006</th>\n",
       "      <th>m0612</th>\n",
       "      <th>m1218</th>\n",
       "      <th>f0006</th>\n",
       "      <th>f0612</th>\n",
       "      <th>f1218</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1.0</td>\n",
       "      <td>Mickéy Mousé</td>\n",
       "      <td>56.0</td>\n",
       "      <td>70kgs</td>\n",
       "      <td>72</td>\n",
       "      <td>69</td>\n",
       "      <td>71</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2.0</td>\n",
       "      <td>Donald Duck</td>\n",
       "      <td>34.0</td>\n",
       "      <td>154.89lbs</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>85</td>\n",
       "      <td>84</td>\n",
       "      <td>76</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3.0</td>\n",
       "      <td>Mini Mouse</td>\n",
       "      <td>16.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>65</td>\n",
       "      <td>69</td>\n",
       "      <td>72</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4.0</td>\n",
       "      <td>Scrooge McDuck</td>\n",
       "      <td>NaN</td>\n",
       "      <td>78kgs</td>\n",
       "      <td>78</td>\n",
       "      <td>79</td>\n",
       "      <td>72</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>5.0</td>\n",
       "      <td>Pink Panther</td>\n",
       "      <td>54.0</td>\n",
       "      <td>198.658lbs</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>69</td>\n",
       "      <td>NaN</td>\n",
       "      <td>75</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>6.0</td>\n",
       "      <td>Huey McDuck</td>\n",
       "      <td>52.0</td>\n",
       "      <td>189lbs</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>68</td>\n",
       "      <td>75</td>\n",
       "      <td>72</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>7.0</td>\n",
       "      <td>Dewey McDuck</td>\n",
       "      <td>19.0</td>\n",
       "      <td>56kgs</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>71</td>\n",
       "      <td>78</td>\n",
       "      <td>75</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>8.0</td>\n",
       "      <td>Scööpy Doo</td>\n",
       "      <td>32.0</td>\n",
       "      <td>78kgs</td>\n",
       "      <td>78</td>\n",
       "      <td>76</td>\n",
       "      <td>75</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>9.0</td>\n",
       "      <td>Huey McDuck</td>\n",
       "      <td>52.0</td>\n",
       "      <td>189lbs</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>68</td>\n",
       "      <td>75</td>\n",
       "      <td>72</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>10.0</td>\n",
       "      <td>Louie McDuck</td>\n",
       "      <td>12.0</td>\n",
       "      <td>45kgs</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>92</td>\n",
       "      <td>95</td>\n",
       "      <td>87</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      id            name   age      weight m0006 m0612 m1218 f0006 f0612 f1218\n",
       "0    1.0    Mickéy Mousé  56.0       70kgs    72    69    71     -     -     -\n",
       "1    2.0     Donald Duck  34.0   154.89lbs     -     -     -    85    84    76\n",
       "2    3.0      Mini Mouse  16.0         NaN     -     -     -    65    69    72\n",
       "3    4.0  Scrooge McDuck   NaN       78kgs    78    79    72     -     -     -\n",
       "4    5.0    Pink Panther  54.0  198.658lbs     -     -     -    69   NaN    75\n",
       "5    6.0     Huey McDuck  52.0      189lbs     -     -     -    68    75    72\n",
       "6    7.0    Dewey McDuck  19.0       56kgs     -     -     -    71    78    75\n",
       "7    8.0      Scööpy Doo  32.0       78kgs    78    76    75     -     -     -\n",
       "8    NaN             NaN   NaN         NaN   NaN   NaN   NaN   NaN   NaN   NaN\n",
       "9    9.0     Huey McDuck  52.0      189lbs     -     -     -    68    75    72\n",
       "10  10.0    Louie McDuck  12.0       45kgs     -     -     -    92    95    87"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "column_name=['id','name','age','weight','m0006','m0612','m1218','f0006','f0612','f1218']\n",
    "df = pd.read_csv('./data/patient_heart_rate.csv',names = column_name)\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "35639cb7",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 使用 str.split(expand=True),将列表拆成新的列，再将原来的 Name 列删除\n",
    "df[['first_name','last_name']] = df['name'].str.split(expand=True)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "fe69e267",
   "metadata": {},
   "outputs": [],
   "source": [
    "df.drop('name',axis=1,inplace=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "f738e057",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>id</th>\n",
       "      <th>age</th>\n",
       "      <th>weight</th>\n",
       "      <th>m0006</th>\n",
       "      <th>m0612</th>\n",
       "      <th>m1218</th>\n",
       "      <th>f0006</th>\n",
       "      <th>f0612</th>\n",
       "      <th>f1218</th>\n",
       "      <th>first_name</th>\n",
       "      <th>last_name</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1.0</td>\n",
       "      <td>56.0</td>\n",
       "      <td>70kgs</td>\n",
       "      <td>72</td>\n",
       "      <td>69</td>\n",
       "      <td>71</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>Mickéy</td>\n",
       "      <td>Mousé</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2.0</td>\n",
       "      <td>34.0</td>\n",
       "      <td>154.89lbs</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>85</td>\n",
       "      <td>84</td>\n",
       "      <td>76</td>\n",
       "      <td>Donald</td>\n",
       "      <td>Duck</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3.0</td>\n",
       "      <td>16.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>65</td>\n",
       "      <td>69</td>\n",
       "      <td>72</td>\n",
       "      <td>Mini</td>\n",
       "      <td>Mouse</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>78kgs</td>\n",
       "      <td>78</td>\n",
       "      <td>79</td>\n",
       "      <td>72</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>Scrooge</td>\n",
       "      <td>McDuck</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>5.0</td>\n",
       "      <td>54.0</td>\n",
       "      <td>198.658lbs</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>69</td>\n",
       "      <td>NaN</td>\n",
       "      <td>75</td>\n",
       "      <td>Pink</td>\n",
       "      <td>Panther</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>6.0</td>\n",
       "      <td>52.0</td>\n",
       "      <td>189lbs</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>68</td>\n",
       "      <td>75</td>\n",
       "      <td>72</td>\n",
       "      <td>Huey</td>\n",
       "      <td>McDuck</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>7.0</td>\n",
       "      <td>19.0</td>\n",
       "      <td>56kgs</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>71</td>\n",
       "      <td>78</td>\n",
       "      <td>75</td>\n",
       "      <td>Dewey</td>\n",
       "      <td>McDuck</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>8.0</td>\n",
       "      <td>32.0</td>\n",
       "      <td>78kgs</td>\n",
       "      <td>78</td>\n",
       "      <td>76</td>\n",
       "      <td>75</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>Scööpy</td>\n",
       "      <td>Doo</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>9.0</td>\n",
       "      <td>52.0</td>\n",
       "      <td>189lbs</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>68</td>\n",
       "      <td>75</td>\n",
       "      <td>72</td>\n",
       "      <td>Huey</td>\n",
       "      <td>McDuck</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>10.0</td>\n",
       "      <td>12.0</td>\n",
       "      <td>45kgs</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>92</td>\n",
       "      <td>95</td>\n",
       "      <td>87</td>\n",
       "      <td>Louie</td>\n",
       "      <td>McDuck</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      id   age      weight m0006 m0612 m1218 f0006 f0612 f1218 first_name  \\\n",
       "0    1.0  56.0       70kgs    72    69    71     -     -     -     Mickéy   \n",
       "1    2.0  34.0   154.89lbs     -     -     -    85    84    76     Donald   \n",
       "2    3.0  16.0         NaN     -     -     -    65    69    72       Mini   \n",
       "3    4.0   NaN       78kgs    78    79    72     -     -     -    Scrooge   \n",
       "4    5.0  54.0  198.658lbs     -     -     -    69   NaN    75       Pink   \n",
       "5    6.0  52.0      189lbs     -     -     -    68    75    72       Huey   \n",
       "6    7.0  19.0       56kgs     -     -     -    71    78    75      Dewey   \n",
       "7    8.0  32.0       78kgs    78    76    75     -     -     -     Scööpy   \n",
       "8    NaN   NaN         NaN   NaN   NaN   NaN   NaN   NaN   NaN        NaN   \n",
       "9    9.0  52.0      189lbs     -     -     -    68    75    72       Huey   \n",
       "10  10.0  12.0       45kgs     -     -     -    92    95    87      Louie   \n",
       "\n",
       "   last_name  \n",
       "0      Mousé  \n",
       "1       Duck  \n",
       "2      Mouse  \n",
       "3     McDuck  \n",
       "4    Panther  \n",
       "5     McDuck  \n",
       "6     McDuck  \n",
       "7        Doo  \n",
       "8        NaN  \n",
       "9     McDuck  \n",
       "10    McDuck  "
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.head(11)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "204bdcb8",
   "metadata": {},
   "outputs": [],
   "source": [
    "lbs_weight_s = df[df.weight.str.contains(\"lbs\").fillna(False)]['weight']\n",
    "lbs_weight_s = lbs_weight_s.apply(lambda lbs:  \"%.2fkgs\" % (float(lbs[:-3])/2.2)  )\n",
    "df.loc[lbs_weight_s.index,'weight'] = lbs_weight_s"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "25e514fc",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>id</th>\n",
       "      <th>age</th>\n",
       "      <th>weight</th>\n",
       "      <th>m0006</th>\n",
       "      <th>m0612</th>\n",
       "      <th>m1218</th>\n",
       "      <th>f0006</th>\n",
       "      <th>f0612</th>\n",
       "      <th>f1218</th>\n",
       "      <th>first_name</th>\n",
       "      <th>last_name</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1.0</td>\n",
       "      <td>56.0</td>\n",
       "      <td>70kgs</td>\n",
       "      <td>72</td>\n",
       "      <td>69</td>\n",
       "      <td>71</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>Mickéy</td>\n",
       "      <td>Mousé</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2.0</td>\n",
       "      <td>34.0</td>\n",
       "      <td>70.40kgs</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>85</td>\n",
       "      <td>84</td>\n",
       "      <td>76</td>\n",
       "      <td>Donald</td>\n",
       "      <td>Duck</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3.0</td>\n",
       "      <td>16.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>65</td>\n",
       "      <td>69</td>\n",
       "      <td>72</td>\n",
       "      <td>Mini</td>\n",
       "      <td>Mouse</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>78kgs</td>\n",
       "      <td>78</td>\n",
       "      <td>79</td>\n",
       "      <td>72</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>Scrooge</td>\n",
       "      <td>McDuck</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>5.0</td>\n",
       "      <td>54.0</td>\n",
       "      <td>90.30kgs</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>69</td>\n",
       "      <td>NaN</td>\n",
       "      <td>75</td>\n",
       "      <td>Pink</td>\n",
       "      <td>Panther</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>6.0</td>\n",
       "      <td>52.0</td>\n",
       "      <td>85.91kgs</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>68</td>\n",
       "      <td>75</td>\n",
       "      <td>72</td>\n",
       "      <td>Huey</td>\n",
       "      <td>McDuck</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>7.0</td>\n",
       "      <td>19.0</td>\n",
       "      <td>56kgs</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>71</td>\n",
       "      <td>78</td>\n",
       "      <td>75</td>\n",
       "      <td>Dewey</td>\n",
       "      <td>McDuck</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>8.0</td>\n",
       "      <td>32.0</td>\n",
       "      <td>78kgs</td>\n",
       "      <td>78</td>\n",
       "      <td>76</td>\n",
       "      <td>75</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>Scööpy</td>\n",
       "      <td>Doo</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>9.0</td>\n",
       "      <td>52.0</td>\n",
       "      <td>85.91kgs</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>68</td>\n",
       "      <td>75</td>\n",
       "      <td>72</td>\n",
       "      <td>Huey</td>\n",
       "      <td>McDuck</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    id   age    weight m0006 m0612 m1218 f0006 f0612 f1218 first_name  \\\n",
       "0  1.0  56.0     70kgs    72    69    71     -     -     -     Mickéy   \n",
       "1  2.0  34.0  70.40kgs     -     -     -    85    84    76     Donald   \n",
       "2  3.0  16.0       NaN     -     -     -    65    69    72       Mini   \n",
       "3  4.0   NaN     78kgs    78    79    72     -     -     -    Scrooge   \n",
       "4  5.0  54.0  90.30kgs     -     -     -    69   NaN    75       Pink   \n",
       "5  6.0  52.0  85.91kgs     -     -     -    68    75    72       Huey   \n",
       "6  7.0  19.0     56kgs     -     -     -    71    78    75      Dewey   \n",
       "7  8.0  32.0     78kgs    78    76    75     -     -     -     Scööpy   \n",
       "8  NaN   NaN       NaN   NaN   NaN   NaN   NaN   NaN   NaN        NaN   \n",
       "9  9.0  52.0  85.91kgs     -     -     -    68    75    72       Huey   \n",
       "\n",
       "  last_name  \n",
       "0     Mousé  \n",
       "1      Duck  \n",
       "2     Mouse  \n",
       "3    McDuck  \n",
       "4   Panther  \n",
       "5    McDuck  \n",
       "6    McDuck  \n",
       "7       Doo  \n",
       "8       NaN  \n",
       "9    McDuck  "
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.head(10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "6302d000",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>id</th>\n",
       "      <th>age</th>\n",
       "      <th>weight</th>\n",
       "      <th>m0006</th>\n",
       "      <th>m0612</th>\n",
       "      <th>m1218</th>\n",
       "      <th>f0006</th>\n",
       "      <th>f0612</th>\n",
       "      <th>f1218</th>\n",
       "      <th>first_name</th>\n",
       "      <th>last_name</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1.0</td>\n",
       "      <td>56.0</td>\n",
       "      <td>70kgs</td>\n",
       "      <td>72</td>\n",
       "      <td>69</td>\n",
       "      <td>71</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>Mickéy</td>\n",
       "      <td>Mousé</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2.0</td>\n",
       "      <td>34.0</td>\n",
       "      <td>70.40kgs</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>85</td>\n",
       "      <td>84</td>\n",
       "      <td>76</td>\n",
       "      <td>Donald</td>\n",
       "      <td>Duck</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3.0</td>\n",
       "      <td>16.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>65</td>\n",
       "      <td>69</td>\n",
       "      <td>72</td>\n",
       "      <td>Mini</td>\n",
       "      <td>Mouse</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>78kgs</td>\n",
       "      <td>78</td>\n",
       "      <td>79</td>\n",
       "      <td>72</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>Scrooge</td>\n",
       "      <td>McDuck</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>5.0</td>\n",
       "      <td>54.0</td>\n",
       "      <td>90.30kgs</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>69</td>\n",
       "      <td>NaN</td>\n",
       "      <td>75</td>\n",
       "      <td>Pink</td>\n",
       "      <td>Panther</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>6.0</td>\n",
       "      <td>52.0</td>\n",
       "      <td>85.91kgs</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>68</td>\n",
       "      <td>75</td>\n",
       "      <td>72</td>\n",
       "      <td>Huey</td>\n",
       "      <td>McDuck</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>7.0</td>\n",
       "      <td>19.0</td>\n",
       "      <td>56kgs</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>71</td>\n",
       "      <td>78</td>\n",
       "      <td>75</td>\n",
       "      <td>Dewey</td>\n",
       "      <td>McDuck</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>8.0</td>\n",
       "      <td>32.0</td>\n",
       "      <td>78kgs</td>\n",
       "      <td>78</td>\n",
       "      <td>76</td>\n",
       "      <td>75</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>Scööpy</td>\n",
       "      <td>Doo</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>10.0</td>\n",
       "      <td>12.0</td>\n",
       "      <td>45kgs</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>92</td>\n",
       "      <td>95</td>\n",
       "      <td>87</td>\n",
       "      <td>Louie</td>\n",
       "      <td>McDuck</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      id   age    weight m0006 m0612 m1218 f0006 f0612 f1218 first_name  \\\n",
       "0    1.0  56.0     70kgs    72    69    71     -     -     -     Mickéy   \n",
       "1    2.0  34.0  70.40kgs     -     -     -    85    84    76     Donald   \n",
       "2    3.0  16.0       NaN     -     -     -    65    69    72       Mini   \n",
       "3    4.0   NaN     78kgs    78    79    72     -     -     -    Scrooge   \n",
       "4    5.0  54.0  90.30kgs     -     -     -    69   NaN    75       Pink   \n",
       "5    6.0  52.0  85.91kgs     -     -     -    68    75    72       Huey   \n",
       "6    7.0  19.0     56kgs     -     -     -    71    78    75      Dewey   \n",
       "7    8.0  32.0     78kgs    78    76    75     -     -     -     Scööpy   \n",
       "8    NaN   NaN       NaN   NaN   NaN   NaN   NaN   NaN   NaN        NaN   \n",
       "10  10.0  12.0     45kgs     -     -     -    92    95    87      Louie   \n",
       "\n",
       "   last_name  \n",
       "0      Mousé  \n",
       "1       Duck  \n",
       "2      Mouse  \n",
       "3     McDuck  \n",
       "4    Panther  \n",
       "5     McDuck  \n",
       "6     McDuck  \n",
       "7        Doo  \n",
       "8        NaN  \n",
       "10    McDuck  "
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 校验两列信息是否重复，删除重复的值\n",
    "df.drop_duplicates(['first_name','last_name'],inplace=True)\n",
    "df.head(10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "f1e5903a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>id</th>\n",
       "      <th>age</th>\n",
       "      <th>weight</th>\n",
       "      <th>m0006</th>\n",
       "      <th>m0612</th>\n",
       "      <th>m1218</th>\n",
       "      <th>f0006</th>\n",
       "      <th>f0612</th>\n",
       "      <th>f1218</th>\n",
       "      <th>first_name</th>\n",
       "      <th>last_name</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1.0</td>\n",
       "      <td>56.0</td>\n",
       "      <td>70kgs</td>\n",
       "      <td>72</td>\n",
       "      <td>69</td>\n",
       "      <td>71</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>Mickéy</td>\n",
       "      <td>Mousé</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2.0</td>\n",
       "      <td>34.0</td>\n",
       "      <td>70.40kgs</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>85</td>\n",
       "      <td>84</td>\n",
       "      <td>76</td>\n",
       "      <td>Donald</td>\n",
       "      <td>Duck</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3.0</td>\n",
       "      <td>16.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>65</td>\n",
       "      <td>69</td>\n",
       "      <td>72</td>\n",
       "      <td>Mini</td>\n",
       "      <td>Mouse</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>78kgs</td>\n",
       "      <td>78</td>\n",
       "      <td>79</td>\n",
       "      <td>72</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>Scrooge</td>\n",
       "      <td>McDuck</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>5.0</td>\n",
       "      <td>54.0</td>\n",
       "      <td>90.30kgs</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>69</td>\n",
       "      <td>NaN</td>\n",
       "      <td>75</td>\n",
       "      <td>Pink</td>\n",
       "      <td>Panther</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>6.0</td>\n",
       "      <td>52.0</td>\n",
       "      <td>85.91kgs</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>68</td>\n",
       "      <td>75</td>\n",
       "      <td>72</td>\n",
       "      <td>Huey</td>\n",
       "      <td>McDuck</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>7.0</td>\n",
       "      <td>19.0</td>\n",
       "      <td>56kgs</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>71</td>\n",
       "      <td>78</td>\n",
       "      <td>75</td>\n",
       "      <td>Dewey</td>\n",
       "      <td>McDuck</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>10.0</td>\n",
       "      <td>12.0</td>\n",
       "      <td>45kgs</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>92</td>\n",
       "      <td>95</td>\n",
       "      <td>87</td>\n",
       "      <td>Louie</td>\n",
       "      <td>McDuck</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      id   age    weight m0006 m0612 m1218 f0006 f0612 f1218 first_name  \\\n",
       "0    1.0  56.0     70kgs    72    69    71     -     -     -     Mickéy   \n",
       "1    2.0  34.0  70.40kgs     -     -     -    85    84    76     Donald   \n",
       "2    3.0  16.0       NaN     -     -     -    65    69    72       Mini   \n",
       "3    4.0   NaN     78kgs    78    79    72     -     -     -    Scrooge   \n",
       "4    5.0  54.0  90.30kgs     -     -     -    69   NaN    75       Pink   \n",
       "5    6.0  52.0  85.91kgs     -     -     -    68    75    72       Huey   \n",
       "6    7.0  19.0     56kgs     -     -     -    71    78    75      Dewey   \n",
       "10  10.0  12.0     45kgs     -     -     -    92    95    87      Louie   \n",
       "\n",
       "   last_name  \n",
       "0      Mousé  \n",
       "1       Duck  \n",
       "2      Mouse  \n",
       "3     McDuck  \n",
       "4    Panther  \n",
       "5     McDuck  \n",
       "6     McDuck  \n",
       "10    McDuck  "
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 删除weight字段重复的数据\n",
    "df.drop_duplicates(['weight'],inplace=True)\n",
    "df.head(10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "65b54376",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>id</th>\n",
       "      <th>age</th>\n",
       "      <th>weight</th>\n",
       "      <th>m0006</th>\n",
       "      <th>m0612</th>\n",
       "      <th>m1218</th>\n",
       "      <th>f0006</th>\n",
       "      <th>f0612</th>\n",
       "      <th>f1218</th>\n",
       "      <th>first_name</th>\n",
       "      <th>last_name</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1.0</td>\n",
       "      <td>56.0</td>\n",
       "      <td>70kgs</td>\n",
       "      <td>72</td>\n",
       "      <td>69</td>\n",
       "      <td>71</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>Micky</td>\n",
       "      <td>Mous</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2.0</td>\n",
       "      <td>34.0</td>\n",
       "      <td>70.40kgs</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>85</td>\n",
       "      <td>84</td>\n",
       "      <td>76</td>\n",
       "      <td>Donald</td>\n",
       "      <td>Duck</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3.0</td>\n",
       "      <td>16.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>65</td>\n",
       "      <td>69</td>\n",
       "      <td>72</td>\n",
       "      <td>Mini</td>\n",
       "      <td>Mouse</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>78kgs</td>\n",
       "      <td>78</td>\n",
       "      <td>79</td>\n",
       "      <td>72</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>Scrooge</td>\n",
       "      <td>McDuck</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>5.0</td>\n",
       "      <td>54.0</td>\n",
       "      <td>90.30kgs</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>-</td>\n",
       "      <td>69</td>\n",
       "      <td>NaN</td>\n",
       "      <td>75</td>\n",
       "      <td>Pink</td>\n",
       "      <td>Panther</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    id   age    weight m0006 m0612 m1218 f0006 f0612 f1218 first_name  \\\n",
       "0  1.0  56.0     70kgs    72    69    71     -     -     -      Micky   \n",
       "1  2.0  34.0  70.40kgs     -     -     -    85    84    76     Donald   \n",
       "2  3.0  16.0       NaN     -     -     -    65    69    72       Mini   \n",
       "3  4.0   NaN     78kgs    78    79    72     -     -     -    Scrooge   \n",
       "4  5.0  54.0  90.30kgs     -     -     -    69   NaN    75       Pink   \n",
       "\n",
       "  last_name  \n",
       "0      Mous  \n",
       "1      Duck  \n",
       "2     Mouse  \n",
       "3    McDuck  \n",
       "4   Panther  "
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 删除在 Fristname 和 Lastname 中 非 ASCII 的字符\n",
    "df['first_name'].replace({r'[^\\x00-\\x7F]+':''}, regex=True, inplace=True)\n",
    "df['last_name'].replace({r'[^\\x00-\\x7F]+':''}, regex=True, inplace=True)\n",
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "eb7296b2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>index</th>\n",
       "      <th>id</th>\n",
       "      <th>age</th>\n",
       "      <th>weight</th>\n",
       "      <th>first_name</th>\n",
       "      <th>last_name</th>\n",
       "      <th>puls_rate</th>\n",
       "      <th>sex</th>\n",
       "      <th>hour</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>56.0</td>\n",
       "      <td>70kgs</td>\n",
       "      <td>Micky</td>\n",
       "      <td>Mous</td>\n",
       "      <td>72</td>\n",
       "      <td>男</td>\n",
       "      <td>0006</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>8</td>\n",
       "      <td>1.0</td>\n",
       "      <td>56.0</td>\n",
       "      <td>70kgs</td>\n",
       "      <td>Micky</td>\n",
       "      <td>Mous</td>\n",
       "      <td>69</td>\n",
       "      <td>男</td>\n",
       "      <td>0612</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>16</td>\n",
       "      <td>1.0</td>\n",
       "      <td>56.0</td>\n",
       "      <td>70kgs</td>\n",
       "      <td>Micky</td>\n",
       "      <td>Mous</td>\n",
       "      <td>71</td>\n",
       "      <td>男</td>\n",
       "      <td>1218</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>25</td>\n",
       "      <td>2.0</td>\n",
       "      <td>34.0</td>\n",
       "      <td>70.40kgs</td>\n",
       "      <td>Donald</td>\n",
       "      <td>Duck</td>\n",
       "      <td>85</td>\n",
       "      <td>女</td>\n",
       "      <td>0006</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>33</td>\n",
       "      <td>2.0</td>\n",
       "      <td>34.0</td>\n",
       "      <td>70.40kgs</td>\n",
       "      <td>Donald</td>\n",
       "      <td>Duck</td>\n",
       "      <td>84</td>\n",
       "      <td>女</td>\n",
       "      <td>0612</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>41</td>\n",
       "      <td>2.0</td>\n",
       "      <td>34.0</td>\n",
       "      <td>70.40kgs</td>\n",
       "      <td>Donald</td>\n",
       "      <td>Duck</td>\n",
       "      <td>76</td>\n",
       "      <td>女</td>\n",
       "      <td>1218</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>28</td>\n",
       "      <td>5.0</td>\n",
       "      <td>54.0</td>\n",
       "      <td>90.30kgs</td>\n",
       "      <td>Pink</td>\n",
       "      <td>Panther</td>\n",
       "      <td>69</td>\n",
       "      <td>女</td>\n",
       "      <td>0006</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>44</td>\n",
       "      <td>5.0</td>\n",
       "      <td>54.0</td>\n",
       "      <td>90.30kgs</td>\n",
       "      <td>Pink</td>\n",
       "      <td>Panther</td>\n",
       "      <td>75</td>\n",
       "      <td>女</td>\n",
       "      <td>1218</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>29</td>\n",
       "      <td>6.0</td>\n",
       "      <td>52.0</td>\n",
       "      <td>85.91kgs</td>\n",
       "      <td>Huey</td>\n",
       "      <td>McDuck</td>\n",
       "      <td>68</td>\n",
       "      <td>女</td>\n",
       "      <td>0006</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>37</td>\n",
       "      <td>6.0</td>\n",
       "      <td>52.0</td>\n",
       "      <td>85.91kgs</td>\n",
       "      <td>Huey</td>\n",
       "      <td>McDuck</td>\n",
       "      <td>75</td>\n",
       "      <td>女</td>\n",
       "      <td>0612</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>45</td>\n",
       "      <td>6.0</td>\n",
       "      <td>52.0</td>\n",
       "      <td>85.91kgs</td>\n",
       "      <td>Huey</td>\n",
       "      <td>McDuck</td>\n",
       "      <td>72</td>\n",
       "      <td>女</td>\n",
       "      <td>1218</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>30</td>\n",
       "      <td>7.0</td>\n",
       "      <td>19.0</td>\n",
       "      <td>56kgs</td>\n",
       "      <td>Dewey</td>\n",
       "      <td>McDuck</td>\n",
       "      <td>71</td>\n",
       "      <td>女</td>\n",
       "      <td>0006</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>38</td>\n",
       "      <td>7.0</td>\n",
       "      <td>19.0</td>\n",
       "      <td>56kgs</td>\n",
       "      <td>Dewey</td>\n",
       "      <td>McDuck</td>\n",
       "      <td>78</td>\n",
       "      <td>女</td>\n",
       "      <td>0612</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>46</td>\n",
       "      <td>7.0</td>\n",
       "      <td>19.0</td>\n",
       "      <td>56kgs</td>\n",
       "      <td>Dewey</td>\n",
       "      <td>McDuck</td>\n",
       "      <td>75</td>\n",
       "      <td>女</td>\n",
       "      <td>1218</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>31</td>\n",
       "      <td>10.0</td>\n",
       "      <td>12.0</td>\n",
       "      <td>45kgs</td>\n",
       "      <td>Louie</td>\n",
       "      <td>McDuck</td>\n",
       "      <td>92</td>\n",
       "      <td>女</td>\n",
       "      <td>0006</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>39</td>\n",
       "      <td>10.0</td>\n",
       "      <td>12.0</td>\n",
       "      <td>45kgs</td>\n",
       "      <td>Louie</td>\n",
       "      <td>McDuck</td>\n",
       "      <td>95</td>\n",
       "      <td>女</td>\n",
       "      <td>0612</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>47</td>\n",
       "      <td>10.0</td>\n",
       "      <td>12.0</td>\n",
       "      <td>45kgs</td>\n",
       "      <td>Louie</td>\n",
       "      <td>McDuck</td>\n",
       "      <td>87</td>\n",
       "      <td>女</td>\n",
       "      <td>1218</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    index    id   age    weight first_name last_name puls_rate sex  hour\n",
       "0       0   1.0  56.0     70kgs      Micky      Mous        72   男  0006\n",
       "1       8   1.0  56.0     70kgs      Micky      Mous        69   男  0612\n",
       "2      16   1.0  56.0     70kgs      Micky      Mous        71   男  1218\n",
       "3      25   2.0  34.0  70.40kgs     Donald      Duck        85   女  0006\n",
       "4      33   2.0  34.0  70.40kgs     Donald      Duck        84   女  0612\n",
       "5      41   2.0  34.0  70.40kgs     Donald      Duck        76   女  1218\n",
       "6      28   5.0  54.0  90.30kgs       Pink   Panther        69   女  0006\n",
       "7      44   5.0  54.0  90.30kgs       Pink   Panther        75   女  1218\n",
       "8      29   6.0  52.0  85.91kgs       Huey    McDuck        68   女  0006\n",
       "9      37   6.0  52.0  85.91kgs       Huey    McDuck        75   女  0612\n",
       "10     45   6.0  52.0  85.91kgs       Huey    McDuck        72   女  1218\n",
       "11     30   7.0  19.0     56kgs      Dewey    McDuck        71   女  0006\n",
       "12     38   7.0  19.0     56kgs      Dewey    McDuck        78   女  0612\n",
       "13     46   7.0  19.0     56kgs      Dewey    McDuck        75   女  1218\n",
       "14     31  10.0  12.0     45kgs      Louie    McDuck        92   女  0006\n",
       "15     39  10.0  12.0     45kgs      Louie    McDuck        95   女  0612\n",
       "16     47  10.0  12.0     45kgs      Louie    McDuck        87   女  1218"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sorted_columns = ['id','age','weight','first_name','last_name']\n",
    "df = pd.melt(df,\n",
    "             id_vars=sorted_columns,\n",
    "             var_name='sex_hour',\n",
    "             value_name='puls_rate')\n",
    "df = df[df.puls_rate != '-'].dropna()\n",
    "df = df.sort_values(['id','first_name','last_name']).reset_index()\n",
    "def split_sex_date(sex_hour):\n",
    "    sex = sex_hour[:1]\n",
    "    if 'f' == sex:\n",
    "        sex = '女'\n",
    "    elif 'm' == sex:\n",
    "        sex = '男'\n",
    "    hour = sex_hour[1:]\n",
    "    return pd.Series([sex,hour])\n",
    "df[['sex','hour']] = df.sex_hour.apply(split_sex_date)\n",
    "df.drop('sex_hour',axis=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "85865f82",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
